﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Text.RegularExpressions;

namespace Twittit.DataAccess
{
    partial class Twit
    {
        public String mixed
        {
            get
            {
                Regex r = new Regex(@"\#\w+\b");
                String msgLong = this.ConvertUrlsToLinks(this.text);
                return (r.Replace(msgLong, "<a href='Tag.aspx?value=$&'>$&</a>")).Replace("=#", "=");
            }
            set { }
        }

        public override string ToString()
        {
            //String msgShort = this.ShortenURL(this.text);
            return this.ConvertUrlsToLinks(this.text);
        }

        private String ConvertUrlsToLinks(string msg)
        {
            String regex = @"((www\.|(http|https|ftp|news|file)+\:\/\/)[&#95;.a-z0-9-]+\.[a-z0-9\/&#95;:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])";
            Regex r = new Regex(regex, RegexOptions.IgnoreCase);
            return r.Replace(msg, "<a href=\"$1\" title=\"Click to open in a new window or tab\" target=\"&#95;blank\">$1</a>").Replace("href=\"www", "href=\"http://www");
        }
    }
}

    

